# 定义DMRSType结构体
struct DMRSType
    DMRSCongfigurationType::Int64
    GroupHopping::Bool
    SequenceHopping::Bool
    NRSID::Matrix{Float64}
    NumCDMGroupsWithoutData::Int64
    DMRSUpinkR16::Bool
    DMRSUplinkTransformPrecodingR16::Bool
    DMRSTypeAPosition::Float64
    DMRSAdditionalPosition::Float64
    DMRSLength::Int64
    CustomSymbolSet::Matrix{Float64}
    DMRSPortSet::Float64
    NIDNSCID::Matrix{Float64}
    NSCID::Int64
    DMRSEnhancedR18::Bool
    CDMGroups::Int64
    DeltaShifts::Int64
    FrequencyWeights::Vector{Float64}
    TimeWeights::Vector{Float64}
    DMRSSubcarrierLocations::Vector{Float64}
    CDMLengths::Vector{Float64}
end

# 定义PTRSType结构体，包含图中所示的PTRS相关属性
struct PTRSType
    NumPTRSSamples::Float64
    NumPTRSGroups::Float64
    NID::Matrix{Float64}
    PTRSPortSet::Matrix{Float64}
    TimeDensity::Float64
    FrequencyDensity::Float64
    REOffset::String
end

# 定义ReservedConfig结构体
struct nrPUSCHReservedConfigType
    PRBSet::Vector{Float64}
    SymbolSet::Vector{Float64}
    Period::Vector{Float64}
end

# 初始化ReservedConfig实例
reserved_config_instance = nrPUSCHReservedConfigType([], [], [])

# 定义PUSCHConfig结构体
struct PUSCHConfig
    NID::Matrix{Float64}
    NSizeBWP::Matrix{Float64}
    NStartBWP::Matrix{Float64}
    Modulation::String
    TransformPrecoding::Bool
    TransmissionScheme::String
    NumAntennaPorts::Float64
    TPMI::Float64
    CodebookType::String
    BetaOffsetACK::Float64
    BetaOffsetCSI1::Float64
    BetaOffsetCSI2::Float64
    UCIScaling::Float64
    NRAPID::Matrix{Float64}
    DMRS::DMRSType
    PTRS::PTRSType
    NumLayers::Float64
    MappingType::String
    SymbolAllocation::Vector{Float64}
    PRBSet::Matrix{Float64}
    RNTI::Float64
    EnablePTRS::Bool
    NumCodewords::Float64
    FrequencyHopping::String
    SecondHopStartPRB::Float64
    Interlacing::Bool
    InterlaceIndex::Float64
    RBSetIndex::Float64
end

# 定义扩展参数结构体
struct Extension
    TargetCodeRate::Float64
    XOverhead::Float64
end

# 定义包含 PUSCH 配置和扩展参数的结构体
struct PUSCH
    Config::PUSCHConfig
    Extension::Extension
end

function hMultiUserPUSCH(numLayers)
    # 创建一个基础的 DMRSType 实例，根据需求设置初始值
    base_dmrs = DMRSType(
        1,
        false,
        false,
        zeros(Float64, 0, 0),
        2,
        false,
        false,
        2.0,
        1,
        2,
        zeros(Float64, 0, 0),
        0,
        zeros(Float64, 0, 0),
        0,
        false,
        0,
        0,
        [1 ; 1],
        [1 ; 1],
        [0;2;4;6;8;10],
        [1 ; 1]
    )
    # 创建一个基础的 PTRSType 实例，根据需求设置初始值
    base_ptrs = PTRSType(
        2,
        2,
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        1,
        2,
        "00"
    )
    # 创建一个基础的 PUSCH 配置
    pusch = PUSCHConfig(
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        "64QAM",
        false,
        "nonCodebook",
        1.0,
        0,
        "codebook1_ng1n4n1",
        20,
        6.2500,
        6.2500,
        1,
        zeros(Float64, 0, 0),
        base_dmrs,
        base_ptrs,
        1,
        "A",
        [0, 14],
        reshape([4, 9, 14, 19, 24, 27, 32, 36, 40, 45, 50], 11, 1),
        1,
        false,
        1,
        "neither",
        1,
        false,
        0,
        0
    )
    # 创建扩展参数
    extension = Extension(
        0.7539,
        0
    )

    numUEs = length(numLayers)
    PUSCHs = [PUSCH(pusch, extension) for _ in 1:numUEs]

    for ue in 1:numUEs
        # 为每个用户设置层数和 RNTI
        new_config = PUSCHConfig(
            pusch.NID,
            pusch.NSizeBWP,
            pusch.NStartBWP,
            pusch.Modulation,
            pusch.TransformPrecoding,
            pusch.TransmissionScheme,
            pusch.NumAntennaPorts,
            pusch.TPMI,
            pusch.CodebookType,
            pusch.BetaOffsetACK,
            pusch.BetaOffsetCSI1,
            pusch.BetaOffsetCSI2,
            pusch.UCIScaling,
            pusch.NRAPID,
            pusch.DMRS,
            pusch.PTRS,
            Float64(numLayers[ue]),
            pusch.MappingType,
            pusch.SymbolAllocation,
            pusch.PRBSet,
            Float64(ue),
            pusch.EnablePTRS,
            pusch.NumCodewords,
            pusch.FrequencyHopping,
            pusch.SecondHopStartPRB,
            pusch.Interlacing,
            pusch.InterlaceIndex,
            pusch.RBSetIndex
        )
        PUSCHs[ue] = PUSCH(new_config, extension)
    end

    return PUSCHs
end

# 设定 numLayers
numLayers = [1, 4, 4, 2, 4]
PUSCHs = hMultiUserPUSCH(numLayers)
println(PUSCHs)